package com.cll.learn.control.demo01;

import java.util.concurrent.CountDownLatch;

/**
 * 描述信息:
 * 发令枪
 * 主线程等待所有任务结束
 * 所有任务都结束，主线程才会结束
 * @author CLL
 * @version 1.0
 * @date 2021/5/15 16:55
 */
public class CountDownLatchDemo {

    public static void main(String[] args) {
        CountDownLatch countDownLatch = new CountDownLatch(5);
        for (int i = 0; i < 5; i++) {
            new Thread(new WaitThread(countDownLatch)).start();
        }

        try {
            countDownLatch.await();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("===>>> 所有线程准备完成，主线程可以结束了");
    }
}